package com.ptszyxx.popose.module.main.home.adapter;

import android.view.View;

import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.viewholder.BaseDataBindingHolder;
import com.ptszyxx.popose.R;
import com.ptszyxx.popose.common.enums.HomeTabEnum;
import com.ptszyxx.popose.databinding.ItemHomeWorldBinding;
import com.ptszyxx.popose.module.main.home.vm.HomeWorldVM;
import com.tencent.qcloud.tuikit.tuichat.zhiyu.adapter.UserPicAdapter;
import com.ysg.http.data.entity.home.HomeResult;
import com.ysg.utils.YImageUtil;
import com.ysg.utils.YRecyclerViewUtil;
import com.ysg.utils.YSPUtils;
import com.ysg.utils.YStringUtil;

import java.util.ArrayList;
import java.util.List;

public class HomeWorldAdapter extends BaseQuickAdapter<HomeResult, BaseDataBindingHolder<ItemHomeWorldBinding>> {
    private HomeWorldVM viewModel;
    private Presenter mPresenter = new Presenter();
    private String separator = " | ";
    private HomeTabEnum homeTabEnum;


    public HomeWorldAdapter(HomeWorldVM viewModel, HomeTabEnum homeTabEnum) {
        super(R.layout.item_home_world);
        this.viewModel = viewModel;
        this.homeTabEnum = homeTabEnum;
    }

    @Override
    protected void convert(BaseDataBindingHolder<ItemHomeWorldBinding> holder, HomeResult item) {
        ItemHomeWorldBinding binding = holder.getDataBinding();
        if (binding != null) {
            int position = holder.getBindingAdapterPosition();

            binding.setEntity(item);
            binding.setViewModel(viewModel);
            binding.setPresenter(mPresenter);
            binding.setPosition(holder.getBindingAdapterPosition());
            binding.executePendingBindings();

            if (position % 2 == 0){
                HomeWorldPicAdapter adapter = new HomeWorldPicAdapter();
                YRecyclerViewUtil.initHorizontalNoLine(getContext(), binding.recyclerView, adapter);
                List<String> picList = new ArrayList<>();
                picList.add("http://osszhiyuhn1.ptszyxx.com/image/000c60a2c12f4753a2ca5ea82530d203.jpg");
                picList.add("http://osszhiyuhn1.ptszyxx.com/image/0017b136af624b5ca03cd30b002cc026.jpg");
                picList.add("http://osszhiyuhn1.ptszyxx.com/image/00542146c3b742b28621c54791ba4a0b.jpg");
                adapter.setList(picList);
                binding.recyclerView.setVisibility(View.VISIBLE);
            }else{
                binding.recyclerView.setVisibility(View.GONE);
            }


//            YImageUtil.show(binding.ivAvatar, item.getPic());

//            //优先级：语音-》签名-》个人信息
//            if (YStringUtil.isNotEmpty(item.getVoiceSignature())) {
//                binding.voiceView.setData(item.getVoiceSignature(), item.getVoiceSignatureSeconds());
//                binding.voiceView.setVisibility(View.VISIBLE);
//                binding.tvSignature.setVisibility(View.GONE);
//            } else if (YStringUtil.isNotEmpty(item.getQianming())){
//                binding.tvSignature.setText(item.getQianming());
//                binding.voiceView.setVisibility(View.GONE);
//                binding.tvSignature.setVisibility(View.VISIBLE);
//            }
//
//            //个人信息：拼接
            StringBuffer sb = new StringBuffer();
            if (YStringUtil.isNotEmpty(item.getAddress())){
                sb.append(item.getAddress() + separator);
            }
            if (YStringUtil.isNotEmpty(item.getAge() + "") && YStringUtil.noEq(0, item.getAge() + "")){
                sb.append(item.getAge() + getContext().getResources().getString(R.string.year_old) + separator);
            }
            if (YStringUtil.isNotEmpty(item.getShengao())){
                sb.append(item.getShengao() + separator);
            }
            if (YStringUtil.isNotEmpty(item.getZhiyename())){
                sb.append(item.getZhiyename() + separator);
            }
            binding.tvInfo.setText(YStringUtil.clearEnd(sb.toString(), separator));
//
//            if (HomeTabEnum.account == homeTabEnum){
//                binding.ivSayHello.setVisibility(View.GONE);
//                if (YStringUtil.eq(YSPUtils.getInstance().getUserPhone(), item.getLoginname())){
//                    binding.tvCurrentAccount.setVisibility(View.VISIBLE);
//                }
//            }

        }
    }

    public static class Presenter{
        public void onItemClick(HomeWorldVM viewModel, HomeResult entity){
            viewModel.jumpPersonDetail(entity);
        }
        public void onChatClick(HomeWorldVM viewModel, HomeResult entity){
            viewModel.jumpChat(entity);
        }
    }







}
